package com.jy.wms.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jy.wms.common.base.BaseController;
import com.jy.wms.common.base.ManySheetOneSyler;
import com.jy.wms.pojo.SysUser;
import com.jy.wms.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: LoginController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author zzp
 * @Date 2017/10/22 10:47
 */
@RestController
@RequestMapping("/test")
@Api(value = "测试",description = "测试接口")
public class LoginController extends BaseController<LoginService,SysUser> {
    protected static Logger logger = LoggerFactory.getLogger(LoginController.class);
    @ApiOperation(value = "用户", notes = "没有条件默认查询所有；page和rows，根据分页信息查询；如果条件查询，按照规范写查询条件即可")
    @GetMapping("/MapExportExcel")
    public void exportMerchantProfitQuery(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.ms-excel");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("用户数据表","UTF-8") + ".xls");
        //编码
        response.setCharacterEncoding("UTF-8");
        //List<User> list = userService.findAll();
        ExportParams ep= new ExportParams("用户信息导出","用户信息导出");
        ep.setStyle(ManySheetOneSyler.class);
        List<SysUser> sysUsers=baseService.selectList(new EntityWrapper().orderBy("id"));
        Workbook workbook = ExcelExportUtil.exportExcel(ep, SysUser.class, sysUsers);
        workbook.write(response.getOutputStream());
    }
    private List<SysUser> getData() {
        List<SysUser> dataResult = new ArrayList<SysUser>();
        SysUser sysUser=new SysUser();
        SysUser sysUser2=new SysUser();
        sysUser.setId("12321");
        sysUser.setMm("zzp");
        sysUser2.setId("123221");
        sysUser2.setMm("zzp2");

        dataResult.add(sysUser);
        dataResult.add(sysUser2);

        return dataResult;
    }
}
